package io.gitee.wminyu.day07.Recursive;

import org.junit.Test;

public class Factorial {

    //循环求阶层
    public void factorial(int num){
        int sum = 1;
        for (int i = 1; i<=num; i++){
            sum*=i;
        }System.out.print(sum);
    }

    //递归求阶乘
    public int factorial2(int num){
        if (num==1){
            return 1;
        }else {
            return factorial2(num-1)*num;
        }
    }

    @Test
    public void test(){
        factorial(5);
    }

    @Test
    public void test2(){
        System.out.print(factorial2(5));
    }
}
